package com.gton.lpl.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gton.lpl.entity.GpItem;
import com.gton.lpl.entity.GpMenu;
import com.gton.lpl.mapper.GpItemMapper;
import com.gton.lpl.mapper.GpMenuMapper;
import com.gton.lpl.service.GpItemService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author GuoTong
 * @since 2021-10-21
 */
@Service
public class GpItemServiceImpl extends ServiceImpl<GpItemMapper, GpItem> implements GpItemService {

    @Resource
    private GpItemMapper gpItemMapper;

    @Resource
    private GpMenuMapper gpMenuMapper;

    @Override
    public boolean addNewItemByParentId(GpItem gpItem) {
        Long menuId = gpItem.getMenuId();
        if (menuId == null || menuId == 0) {
            return false;
        }
        //验证menuID是否合法
        GpMenu menu = gpMenuMapper.selectById(menuId);
        if (Objects.isNull(menu)) {
            return false;
        }
        int insert = gpItemMapper.insert(gpItem);
        return insert > 0;
    }
}
